define(function(require, exports, module) {
	"require:nomunge,exports:nomunge,module:nomunge";
	
    var self = exports;
    var utils = require('mokit/utils');
    var service = require('./service');
    var user = require('./User');
    
	self.type = "works";
	self.imgPath = user.syproUri;
	
	
	/*====列表部分====*/
	self.list = [];
	self.args = {
		workType: "sel",
		pageNo: 0,
		pageSize: 4,	
	};
	self.sortBy = "level";
	self.sortDir = "desc";

	//重置列表
	self.resetList = function(){
		this.list = [];
		this.args.pageNo = 1;
		this.isEnd = false;
	};
	
     //初始化列表
	self.iniList = function(callback){
    	this.resetList();     	
     	this.getList(callback);
	};
	
    //排序列表
    self.sortList = function(sortBy, callback){
     	this.sortDir = this.sortBy==sortBy ? (this.sortDir=="asc"?"desc":"asc") : "desc";
     	this.sortBy = sortBy;
		this.iniList(callback);
    };
    
    //筛选列表
    self.filterList = function(type, val, callback){
     	this.args[type] = val;
		this.iniList(callback);
    };
    
    //加载更多列表
	self.loadMoreList = function(callback){
		if(!this.isEnd){
			this.args.page++;
			this.getList(callback);
		}
	};
	
    //获取列表
	self.getList = function(callback){
        service.works.getList(this.args, function(rs, err) {
            if (err && callback) return callback(err.message || err);
            if (rs.success) {
               	self.list = self.list.concat(rs.obj);
               	self.isEnd = rs.obj.length<self.args.pageSize;
               	var isEmpty = self.args.page>1 && rs.obj.length==0;
                if (callback) callback(!isEmpty);
            } else {
                rs = rs || {};
                var msg = rs.msg || 'unknow error';
                if (callback) callback(msg);
            }
        });
    };
  
	/*====详情部分====*/
	self.workId = 0;	
	self.info = {};
	
    //获取详情
	self.getInfo = function(workId, callback){
		this.workId = workId;
        service.works.getInfo({id:this.workId}, function(rs, err) {
            if (err && callback) return callback(err.message || err);
            if (rs.success) {
               	self.info = rs.obj;
                if (callback) callback();
            } else {
                rs = rs || {};
                var msg = rs.msg || 'unknow error';
                if (callback) callback(msg);
            }
        });    	
    };
	    
	/*====功能部分====*/

	
    //收藏作品
	self.collect = function(callback){
        service.works.collect({Id:this.workId}, function(rs) {
        		callback(rs);
        });    	
    };
});